package com.time.social.controller;

import com.time.social.utils.SHA1;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微信回调服务控制层类
 *
 * @author: HuangQi
 * @date: Created in 14:42 2025/9/30
 * @description: 微信回调服务控制层
 */
@Slf4j
@RestController
@RequestMapping("/wx/")
public class WxController {

    /**
     *  微信Token
     */
    private static final String TOKEN = "timecollector";

    /**
     *  分隔符 .
     */
    private static final String CACHE_KEY_SEPARATOR = ".";


    @RequestMapping("test")
    public String test() {
        return "hello world";
    }

    /**
     * 回调消息校验
     */
    @GetMapping("callback")
    public String callback(@RequestParam("signature") String signature,
                           @RequestParam("timestamp") String timestamp,
                           @RequestParam("nonce") String nonce,
                           @RequestParam("echostr") String echostr) {
        log.info("get验签请求参数：signature:{}，timestamp:{}，nonce:{}，echostr:{}",
                signature, timestamp, nonce, echostr);
        String shaStr = SHA1.getSHA1(TOKEN, timestamp, nonce, "");
        if (signature.equals(shaStr)) {
            return echostr;
        }
        return "unknown";
    }


}